package com.ruoyi.web.controller.warning;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.warning.domain.entity.DevicesPing;
import com.ruoyi.warning.domain.query.DeviceQuery;
import com.ruoyi.warning.service.IDevicesPingService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-09-05
 */
@RestController
@RequestMapping("/devicesPing")
public class DevicesPingController {

    @Resource
    private IDevicesPingService devicesPingService;
    @PostMapping(value = "/exportExcel", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public void exportExcel(@ModelAttribute DeviceQuery deviceQuery, HttpServletResponse response) throws IOException {
        List<DevicesPing> list = devicesPingService.list(new LambdaQueryWrapper<DevicesPing>()
                .eq(DevicesPing::getDeviceId,deviceQuery.getDeviceId())
                .ge(DevicesPing::getInserted,deviceQuery.getStartTime())
                .le(DevicesPing::getInserted,deviceQuery.getEndTime())
                .orderByDesc(DevicesPing::getInserted));
        ExcelUtil<DevicesPing> util = new ExcelUtil<>(DevicesPing.class);
        util.exportExcel(response, list, "资产表");
    }
}
